package com.lhf.aicloud.utils;

import com.lhf.aicloud.entity.SecurityUserDetails;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author: lhf
 * @date: Created in 2024/08/10
 * @description:
 */
public class SecurityUtils {
    /**
     * 获取当前登录用户
     */
    public static SecurityUserDetails getCurrentUser() {
        SecurityUserDetails userDetails = null;
        try {
            userDetails = (SecurityUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        } catch (Exception e) {
            return null;
        }
        return userDetails;
    }
}
